import json

import pandas as pd

# 读取Excel文件
file_path = 'D:\\工作文档\\舌诊算法\\舌诊症状数据20240507.xlsx'
df = pd.read_excel(file_path, header=0, engine='openpyxl')

# 显示前5行数据
json_data = df.to_json(orient='records')
array = json.loads(json_data)
# 所有症状编码集合，之后进行去重
arr_code = []

# 将编码进行去重
for item in array:
    arr_code.append(item['code'])
unique_code = list(set(arr_code))

arr_sum = []
arr_man = []
arr_woman = []
for item in array:
    # 男性病症
    arr_sum.append(item['diseaseManList'])
    # 女性病症
    arr_sum.append(item['diseaseWomanList'])
    # 男
    arr_man.append({"code": item['code'], "disease": item['diseaseManList']})
    # 女
    arr_woman.append({"code": item['code'], "disease": item['diseaseWomanList']})

# 统计有多少病症
unique_name = list(set(arr_sum))
print(json.dumps(unique_name, ensure_ascii=False))

man_result = []
woman_result = []
for code in unique_code:
    # 男
    man_map = []
    for man in arr_man:
        if code == man['code']:
            man_map.append(man['disease'])
    man_result.append({"code": code, "diseaseManList": man_map})

    # 女
    woman_map = []
    for woman in arr_woman:
        if code == woman['code']:
            woman_map.append(woman['disease'])
    woman_result.append({"code": code, "diseaseWomanList": "，".join(woman_map)})

print(man_result)
print(json.dumps(man_result, ensure_ascii=False))
print(json.dumps(woman_result, ensure_ascii=False))
